package com.app.micaihu.bean.news;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.custom.components.downandupload.LoadingView;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.micaihu.listener.AutoHeightControllerListener;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;

/**
 * 游戏图片原生自定义View(适用于文章信息流)可跳转内页
 * Created by linkai on 2017/2/9.
 */
public class ViewGameVideoThree {


    //根布局
    public View mConvertView;

    /************ 控件 *************/
    private CustomImageView smallImg;
    private CustomImageView bigImg;
    private CustomImageView oneImg;
    private CustomImageView twoImg;
    private CustomImageView threeImg;
    private TextView title;
    private TextView time;
    private CustomImageView mark;
    private LoadingView downloadView;//下载按钮


    private int width = 324;
    private int height = 232;
    private AutoHeightControllerListener autoHeightControllerListener;

    public ViewGameVideoThree(View contentView) {
        initView(contentView);
    }

    public ViewGameVideoThree(View contentView, int width, int height) {
        this.width = width;
        this.height = height;
        initView(contentView);
    }

    /**
     * 初始化公共布局
     *
     */
    protected void initView(View convertView) {
        this.mConvertView = convertView;
        this.title = (TextView) mConvertView.findViewById(R.id.item_public_title);
        this.time = (TextView) mConvertView.findViewById(R.id.ad_time);
//        this.time2 = (TextView) findViewById(R.id.ad_time2);
        this.mark = (CustomImageView) mConvertView.findViewById(R.id.ad_mark);
        this.oneImg = (CustomImageView) mConvertView.findViewById(R.id.item_image_0);
        this.twoImg = (CustomImageView) mConvertView.findViewById(R.id.item_image_1);
        this.threeImg = (CustomImageView) mConvertView.findViewById(R.id.item_image_2);
        this.smallImg = (CustomImageView) mConvertView.findViewById(R.id.item_small_image);
        this.bigImg = (CustomImageView) mConvertView.findViewById(R.id.item_large_image);
        this.downloadView = (LoadingView) mConvertView.findViewById(R.id.ad_download);
        LoadImageUtils.getInstance().loadImage(mark, R.drawable.infor_list_home_game,false);
        ViewSizeUtils.changeViewAuto1080(smallImg, width, height);
        ViewSizeUtils.changeViewAuto1080(oneImg, width, height);
        ViewSizeUtils.changeViewAuto1080(twoImg, width, height);
        ViewSizeUtils.changeViewAuto1080(threeImg, width, height);

        autoHeightControllerListener = new AutoHeightControllerListener(this.bigImg,4.35f,1.58f);
        mConvertView.setTag(this);
    }

    /**
     * 设置即将加载的广告
     * @param newsEntity
     */
    public void loadData(NewsEntity newsEntity){
        this.title.setText(newsEntity.getArticleTitle());
        //显示一张图的描述
        this.time.setText(newsEntity.getAppName() + " " + newsEntity.getAppSize());

        if(TextUtils.equals(newsEntity.getUiType(), TypeConstant.NEWS_UI_SMALL_IMG)){

            if(newsEntity.getArticleThumb() !=null && newsEntity.getArticleThumb().length > 0){
                if(newsEntity.getArticleThumb().length < 3){
                    LoadImageUtils.getInstance().loadImage(this.smallImg, newsEntity.getArticleThumb()[0]);
//                    (RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);//两个参数分别是layout_width,layout_height
//                    2.lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);//这个就是添加其他属性的，这个是在父元素的底部。
                    this.oneImg.setVisibility(View.GONE);
                    this.twoImg.setVisibility(View.GONE);
                    this.threeImg.setVisibility(View.GONE);
                    this.smallImg.setVisibility(View.VISIBLE);
                    this.bigImg.setVisibility(View.GONE);

                }else{
                    LoadImageUtils.getInstance().loadImage(this.oneImg, newsEntity.getArticleThumb()[0]);
                    LoadImageUtils.getInstance().loadImage(this.twoImg, newsEntity.getArticleThumb()[1]);
                    LoadImageUtils.getInstance().loadImage(this.threeImg, newsEntity.getArticleThumb()[2]);
                    this.oneImg.setVisibility(View.VISIBLE);
                    this.twoImg.setVisibility(View.VISIBLE);
                    this.threeImg.setVisibility(View.VISIBLE);
                    this.smallImg.setVisibility(View.GONE);
                    this.bigImg.setVisibility(View.GONE);
                }
            }else{
                this.oneImg.setVisibility(View.GONE);
                this.twoImg.setVisibility(View.GONE);
                this.threeImg.setVisibility(View.GONE);
                this.smallImg.setVisibility(View.GONE);
                this.bigImg.setVisibility(View.GONE);
            }
            downloadView.setTag(newsEntity);
        }else if(TextUtils.equals(newsEntity.getUiType(), TypeConstant.NEWS_UI_BIG_ONE_IMG)
                || TextUtils.equals(newsEntity.getUiType(), TypeConstant.NEWS_UI_BIG_TWO_IMG)){



            if(newsEntity.getArticleThumb() !=null && newsEntity.getArticleThumb().length > 0){
                LoadImageUtils.getInstance().loadImage(this.bigImg, newsEntity.getArticleThumb()[0], autoHeightControllerListener);
                this.oneImg.setVisibility(View.GONE);
                this.twoImg.setVisibility(View.GONE);
                this.threeImg.setVisibility(View.GONE);
                this.smallImg.setVisibility(View.GONE);
                this.bigImg.setVisibility(View.VISIBLE);
            }else{
                this.oneImg.setVisibility(View.GONE);
                this.twoImg.setVisibility(View.GONE);
                this.threeImg.setVisibility(View.GONE);
                this.smallImg.setVisibility(View.GONE);
                this.bigImg.setVisibility(View.GONE);
            }
            downloadView.setTag(null);
        }

//        downloadView.setTag(newsEntity);

    }


}
